#!/bin/sh

#create a date variable which will be used to make the log
LOGNM=$(date +"Y%g-W%V");

# try a direct call to the (PCH A110) php interpreter
echo "Attempting to use the PHP binary (at syb8634)...";
if ! /mnt/syb8634/server/php5-cgi -q /share/Apps/NewzBook/webui/include/cronjob.php >> /share/Apps/NewzBook/logs/CRON-$LOGNM.log;
then echo "Attempt to use PHP binary failed"; 
     # if the first command failed, let's try to get the cronjob via wget
     echo "Trying to start the cronjob using web call (wget)...";
     wget -q http://localhost:9999/NewzBook_web/include/cronjob.php -O - >> /share/Apps/NewzBook/logs/CRON-$LOGNM.log;
fi

#remove log files older than 30 days
echo "Removing log files older than 30 days...";
find /share/Apps/NewzBook/logs/ -type f -mtime +30 -exec rm -f {} \;

#save the most up-to date crontab entry to the logs folder
echo "Getting the latest cron entries..."
crontab -l > /share/Apps/NewzBook/logs/cron/cron.txt